<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>字典明细编辑</title>
<link rel="stylesheet" href="<%=basePath %>/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="<%=basePath %>/plugins/bootstraptable/bootstrap-table.css">
    <link rel="stylesheet" href="<%=basePath %>/bootstrap/css/custom-theme/jquery-ui-1.9.2.custom.css">
    <link rel="stylesheet" href="<%=basePath%>/bootstrap/css/bootstrap-multiselect.css">
    <link rel="stylesheet" href="<%=basePath%>/bootstrap/css/bootstrap-datetimepicker.css">
    <link href="<%=basePath %>/plugins/bootstrapValidator/css/bootstrapValidator.min.css"  rel="stylesheet">
    
    
    <script src="<%=basePath %>/js/jquery.min.js"></script>
	<script src="<%=basePath %>/bootstrap/js/bootstrap.min.js"></script>
	<script src="<%=basePath %>/bootstrap/js/bootstrapQ.js"></script>
	<script src="<%=basePath %>/plugins/bootstraptable/bootstrap-table.js"></script>
	<script src="<%=basePath %>/plugins/bootstraptable/locale/bootstrap-table-zh-CN.js"></script>	
	<script src="<%=basePath %>/plugins/bootstraptable/locale/bootstrap-table-editable.js"></script>
	
	<script src="<%=basePath %>/plugins/bootstrapValidator/js/bootstrapValidator.min.js"></script>
	<script src="<%=basePath %>/plugins/bootstrapValidator/js/language/zh_CN.js"></script>
	<script src="<%=basePath%>/bootstrap/js/bootstrap-multiselect.js"></script>
	<script src="<%=basePath %>/js/util.js"></script>
    <script src="<%=basePath %>/plugins/layer/layer.js"></script>
	
	<link rel="stylesheet" href="<%=basePath%>/css/toastr.min.css">
	<script src="<%=basePath%>/js/toastr.min.js"></script>
	<script src="<%=basePath%>/js/toastrinit.js"></script>
	
	<script src="<%=basePath%>/bootstrap/js/bootstrap-datetimepicker.js"	charset="UTF-8"></script>
	<script	src="<%=basePath%>/bootstrap/js/locales/bootstrap-datetimepicker.zh-CN.js"	charset="UTF-8"></script>
<style> 
.table-hover>tbody>tr:hover{background-color:#C6E2FF}
</style>

<script type="text/javascript">
$(document).ready(function(){
	//控件初始化
	    $.ajax({
        url:"<%=basePath%>/dict/getMultiselect.do",
        type:"POST",
        dataType:"json",
        data:{dictionaryCode:"T_DICTIONART_ITEM_STATUS"},
        success:function(data){
            $("#status").multiselect({
                 enableFiltering: false,
                 maxHeight: 300
            });
            $("#status").multiselect('dataprovider',eval(data.jsonData));//数据初始化。如果有数据默认值，则需要参考最上面的代码
            $("#status").multiselect('select','${dictionaryItem.status}' != '' ? '${dictionaryItem.status}' : data.defaultVal); //默认选择值
            $("#status").multiselect('refresh'); //配合默认选择值进行刷新
        }    
	 });
	
	
	  //控件初始化
	    $.ajax({
        url:"<%=basePath%>/dict/getMultiselect.do",
        type:"POST",
        dataType:"json",
        data:{dictionaryCode:"T_DICTIONART_ITEM_ISDEFAULT"},
        success:function(data){
            $("#isDefault").multiselect({
                 enableFiltering: false,
                 maxHeight: 300
            });
            $("#isDefault").multiselect('dataprovider',eval(data.jsonData));//数据初始化。如果有数据默认值，则需要参考最上面的代码
            $("#isDefault").multiselect('select','${dictionaryItem.isDefault}' != '' ? '${dictionaryItem.isDefault}': data.defaultVal); //默认选择值
            $("#isDefault").multiselect('refresh'); //配合默认选择值进行刷新
        }    
	 });
    //控件初始化完毕

    
    $("#dict_item_form").bootstrapValidator();
    //添加
    $("#btn_save").click(function(){
    	  var bootstrapValidator = $("#dict_item_form").data('bootstrapValidator');
    	  bootstrapValidator.resetForm(); //每次验证前都重置验证状态
    	  bootstrapValidator.validate();
    	  if(! bootstrapValidator.isValid()){
    	       return false;
    	  }

    	$.ajax({
    		type:"POST",
			dataType:"json",
            url:"<%=basePath%>/dictItem/save.do",
            data:{
            	id: $("#dictionaryItemId").val(), 
            	dictionaryId:$("#dictionaryId").val(), 
            	itemValue: $("#itemValue").val(),
            	itemName: $("#itemName").val(),
            	itemNameEn:$("#itemNameEn").val(),
            	listOrder: $("#listOrder").val(),
            	isDefault:$("#isDefault").val(),
            	status: $("#status").val()
            },
            success:function(data){
            	if(data.msg == 'error'){
            		toastr.error("<spring:message code='dict.repetition' />");
            	}else{
            		toastr.success("<spring:message code='base.success' />");
                	$("#dictionaryItemId").val(data.id);
                	parent.$("#table").bootstrapTable('refresh');  // 父页面的table刷新
                	parent.parent.$("#table").bootstrapTable('refresh');  // 父页面父页面的table刷新
                	//parent.location.reload(); //父页面整体刷新
	  	            var index = parent.layer.getFrameIndex(window.name); //获取当前窗体索引
	  	            parent.layer.close(index); //执行关闭
                 }           	 
            }
    	 });
    });
    //添加
    $("#btn_add").click(function(){
    	
    });
   
});//document结束
</script>

</head>
<body >
<br/>
<div class="container">


	<!-- 字典明细数据数据 -->	
		<form class="form-horizontal" id = "dict_item_form">
		  <input type="text" class="form-control hide" id="dictionaryItemId" value="${dictionaryItem.id}" >
		  <input type="text" class="form-control hide" id="dictionaryId" value="${dictionaryItem.dictionaryId}" >
		  <div class="form-group">
		    <label for="itemValue" class="col-xs-3 control-label"  style="text-align:right">*<spring:message code='dict.item.itemValue' /></label>
		    <div class="col-xs-8">
		      <input type="text" class="form-control" id="itemValue" name="itemValue" value="${dictionaryItem.itemValue}" required  >
		    </div>
		  </div>
		  <div class="form-group">
		    <label for="itemName" class="col-xs-3 control-label"  style="text-align:right">*<spring:message code='dict.item.itemName' /></label>
		    <div class="col-xs-8">
		      <input type="text" class="form-control" id="itemName" name="itemName"  value="${dictionaryItem.itemName}" required  >
		    </div>
		  </div>
		   <div class="form-group">
		    <label for="itemNameEn" class="col-xs-3 control-label"  style="text-align:right">*<spring:message code='dict.item.itemNameEn' /></label>
		    <div class="col-xs-8">
		      <input type="text" class="form-control" id="itemNameEn" name="itemNameEn"  value="${dictionaryItem.itemNameEn}" required  >
		    </div>
		  </div>
		  <div class="form-group">
		    <label for="listOrder" class="col-xs-3 control-label " style="text-align:right"><spring:message code='dict.item.listOrder' /></label>
		    <div class="col-xs-8">
		      <input type="number"  class="form-control" id="listOrder" name ="listOrder"  value="${dictionaryItem.listOrder}" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" 
		      required  >
		    </div>
		  </div>
		  <div class="form-group">
		    <label for="isDefault" class="col-xs-3 control-label" style="text-align:right" ><spring:message code='dict.item.isDefault' /></label>
		    <div class="col-xs-8">
		        <select id="isDefault"  name = "isDefault" class="form-control" required  ></select>
		    </div>
		  </div> 
		  <div class="form-group">
		    <label for="status" class="col-xs-3 control-label" style="text-align:right"><spring:message code='dict.item.status' /></label>
		    <div class="col-xs-8">
		      <select  id="status" name="status" class="form-control" required  ></select>
		    </div>
		  </div>
		</form>
	</div>
	<div  style="text-align:center">   
		<button id="btn_save"  type="button" class="btn btn-primary"><spring:message code='base.save' /></button>	
	</div>

</body>
</html>